add_executable(profile_get_canonical profile_get_canonical.cc)
add_executable(test_adminusers test_adminusers.cc)
add_executable(test_buffer test_buffer.cc)
add_executable(test_config test_config.cc)
add_executable(test_config_include test_config_include.cc)
add_executable(test_config2 test_config2.cc)
add_executable(test_event test_event.cc)
add_executable(test_filter test_filter.cc)
add_executable(test_hint test_hint.cc)
add_executable(test_http test_http.cc)
add_executable(test_json test_json.cc)
add_executable(test_local_address test_local_address.cc)
add_executable(test_log test_log.cc)
add_executable(test_logorder test_logorder.cc)
add_executable(test_logthrottling test_logthrottling.cc)
add_executable(test_maxscalepcre2 test_maxscalepcre2.cc)
add_executable(test_modulecmd test_modulecmd.cc)
add_executable(test_modutil test_modutil.cc)
add_executable(test_monitor test_monitor.cc)
add_executable(test_poll test_poll.cc)
add_executable(test_server test_server.cc)
add_executable(test_service test_service.cc)
add_executable(test_users test_users.cc)
add_executable(test_utils test_utils.cc)

target_link_libraries(profile_get_canonical maxscale-common)
target_link_libraries(test_adminusers maxscale-common)
target_link_libraries(test_buffer maxscale-common)
target_link_libraries(test_config maxscale-common)
target_link_libraries(test_config_include maxscale-common)
target_link_libraries(test_config2 maxscale-common)
target_link_libraries(test_event maxscale-common)
target_link_libraries(test_filter maxscale-common)
target_link_libraries(test_hint maxscale-common)
target_link_libraries(test_http maxscale-common)
target_link_libraries(test_json maxscale-common)
target_link_libraries(test_local_address maxscale-common)
target_link_libraries(test_log maxscale-common)
target_link_libraries(test_logorder maxscale-common)
target_link_libraries(test_logthrottling maxscale-common)
target_link_libraries(test_maxscalepcre2 maxscale-common)
target_link_libraries(test_modulecmd maxscale-common)
target_link_libraries(test_modutil maxscale-common)
target_link_libraries(test_monitor maxscale-common)
target_link_libraries(test_poll maxscale-common)
target_link_libraries(test_server maxscale-common)
target_link_libraries(test_service maxscale-common)
target_link_libraries(test_users maxscale-common)
target_link_libraries(test_utils maxscale-common)

add_test(test_buffer test_buffer)
add_test(test_config test_config)
add_test(test_config_include test_config_include)
add_test(test_config2 test_config2)
add_test(test_event test_event)
add_test(test_filter test_filter)
add_test(test_hint test_hint)
add_test(test_http test_http)
add_test(test_json test_json)
add_test(test_log test_log)
add_test(NAME test_logorder COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/logorder.sh  200 0 1000 ${CMAKE_CURRENT_BINARY_DIR}/logorder.log)
add_test(test_logthrottling test_logthrottling)
add_test(NAME test_maxpasswd COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test_maxpasswd.sh)
add_test(test_maxscalepcre2 test_maxscalepcre2)
add_test(test_modulecmd test_modulecmd)
add_test(test_modutil test_modutil)
add_test(test_monitor test_monitor)
add_test(test_poll test_poll)
add_test(test_server test_server)
add_test(test_service test_service)
add_test(test_utils test_utils)

add_subdirectory(rest-api)

# GCC 10 has a broken ASAN implementation that got fixed in GCC 11. The
# --as-needed flag breaks the crypt and crypt_r interceptors in ASAN and the
# tests that use it must disble the feature that breaks it. For Debian, adding
# --no-as-needed would fix it but for SLES 15 it still ends up failing. There's
# a bug in SLES 15 where the size of struct crypt_data is different in ASAN than
# it in reality is which causes ASAN itself to trigger a stack overflow that it
# then subsequently reports. To make life simpler, just skip these tests if ASAN
# is enabled on those systems.
if (CRYPT_R_WORKS_WITH_ASAN)
  add_test(test_adminusers test_adminusers)
  add_test(test_users test_users)
else()
  message(STATUS "Skipping test_adminusers and test_users due to broken ASAN implementation")
endif()
